<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>我的成绩</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/score/tes' }">考试</el-breadcrumb-item>
      <el-breadcrumb-item>{{testname}}</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图 -->
    <el-card>
      <!-- 作业列表 -->
      <!-- border加边框 -->
      <!-- stripe隔行变色 -->

      <el-table :data="questionlist" style="width: 100%">
        <el-table-column label="题目ID" prop="id"></el-table-column>
        <el-table-column label="题目名称" prop="details"></el-table-column>
        <el-table-column label="出题者" prop="teacherName"></el-table-column>
        <el-table-column align="right">
          <!-- 与后端联调时需要template, 可能 -->
          <template slot-scope="scope">
            <el-button type="success" @click="nav(scope.$index)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <!-- <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryinfo.pagenum"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="queryinfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>-->
    </el-card>
  </div>
</template>


<script>
export default {
  created() {
    this.getQuestion()
  },
  data() {
    return {
      queryinfo: {
        query: '',
        pagenum: 1,
        pagesize: 2
      },
      questionlist: [],
      uid: this.$store.state.userId,
      total: 0,
      testname: ''
    }
  },
  methods: {
    // 按钮跳转
    // 采取动态路由，保存作业id
    nav(index) {
      console.log(index)
      this.$router.push('/score/tdetail/' + this.questionlist[index].id)
    },

    // 根据作业id，获取该作业包括的题目id数组,存储在questionList中
    async getQuestion() {
      console.log(this.$route.params.id)
      const { data: res } = await this.$http.get(
        'exam/getExamQuestionList/' + this.$route.params.id
      )
      if (res.code !== 200) return this.$message.error(res.message)
      this.testname = Object.keys(res.data)[0]

      this.$store.commit('changeName', { name: this.testname })
      
      this.questionlist = res.data[this.testname]
      console.log(this.questionslist)
    }
  }
}
</script>

<style lang="less" scoped>
</style>